package com.jic.veteran.portal.controller;

import com.google.common.collect.Maps;
import com.jic.veteran.common.api.CommonPage;
import com.jic.veteran.common.api.CommonResult;
import com.jic.veteran.model.*;
import com.jic.veteran.portal.service.AlumniSchoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 获取学校相关信息接口
 * @author mars
 * @date 2021/11/10
 */
@RestController
@Api(tags = "AlumniSchoolController",description = "学校相关信息")
@RequestMapping("/school")
public class AlumniSchoolController {
  @Autowired
  private AlumniSchoolService alumniSchoolService;

  @ApiOperation("查询学校介绍")
  @RequestMapping(value = "/explain", method = RequestMethod.GET)
  public CommonResult<AlumniSchool> getExplain() {
    AlumniSchool alumniSchool = alumniSchoolService.getSchoolExplain();
    return CommonResult.success(alumniSchool);
  }

  @ApiOperation("学校全部新闻")
  @RequestMapping(value = "/allnews", method = RequestMethod.GET)
  @ResponseBody
  public CommonResult<Map<String, List<AlumniSchoolNews>>> getSchoolAllNews() {

    List<AlumniSchoolNews> alumniSchoolNews = alumniSchoolService.getSchoolAllNews();
    Map<String, List<AlumniSchoolNews>> map = Maps.newHashMapWithExpectedSize(20);
    map.put("list", alumniSchoolNews);
    return CommonResult.success(map);
  }


//  @ApiOperation("学校新闻分页")
//  @RequestMapping(value = "/pagenews", method = RequestMethod.POST)
//  @ResponseBody
//  public CommonResult<Map<String, List<AlumniSchoolNews>>> getSchoolPageNews(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
//                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
//
//    List<AlumniSchoolNews> alumniSchoolNews = alumniSchoolService.getSchoolPageNews(pageSize,pageNum);
//    Map<String, List<AlumniSchoolNews>> map = Maps.newHashMapWithExpectedSize(20);
//    map.put("list", alumniSchoolNews);
//    return CommonResult.success(map);
//  }

  @ApiOperation("学校新闻分页")
  @RequestMapping(value = "/pagenews", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult<CommonPage<AlumniSchoolNews>> getSchoolPageNews(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

    List<AlumniSchoolNews> alumniSchoolNews = alumniSchoolService.getSchoolPageNews(pageSize,pageNum);
    return CommonResult.success(CommonPage.restPage(alumniSchoolNews));

  }


  @ApiOperation("单个新闻")
  @RequestMapping(value = "/news", method = RequestMethod.GET)
  public CommonResult<AlumniSchoolNews> getSchoolNews(Long id) {
    AlumniSchoolNews alumniSchoolNews = alumniSchoolService.getSchoolNews(id);
    return CommonResult.success(alumniSchoolNews);
  }


  @ApiOperation("全部周边食宿")
  @RequestMapping(value = "/allaccommodation", method = RequestMethod.GET)
  @ResponseBody
  public CommonResult<Map<String, List<AlumniSchoolAccommodation>>> getAllAccommodation() {
    List<AlumniSchoolAccommodation> alumniSchoolAccommodation = alumniSchoolService.getAllAccommodation();
    Map<String, List<AlumniSchoolAccommodation>> map = Maps.newHashMapWithExpectedSize(20);
    map.put("list", alumniSchoolAccommodation);
    return CommonResult.success(map);
  }

//  @ApiOperation("周边食宿分页")
//  @RequestMapping(value = "/pageaccommodation", method = RequestMethod.GET)
//  @ResponseBody
//  public CommonResult<AlumniInstructions> getPageAccommodation() {
//    return null;
//  }


  @ApiOperation("全部老师")
  @RequestMapping(value = "/teachers", method = RequestMethod.GET)
  @ResponseBody
  public CommonResult<Map<String, List<AlumniSchoolTeachers>>> getTeachers() {
    List<AlumniSchoolTeachers> alumniSchoolTeachers = alumniSchoolService.getTeachers();
    Map<String, List<AlumniSchoolTeachers>> map = Maps.newHashMapWithExpectedSize(20);
    map.put("list", alumniSchoolTeachers);
    return CommonResult.success(map);
  }

//  @ApiOperation("老师分页")
//  @RequestMapping(value = "/pageteachers", method = RequestMethod.POST)
//  @ResponseBody
//  public CommonResult<Map<String, List<AlumniSchoolTeachers>>> getPageTeachers(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
//                                                                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
//
//    List<AlumniSchoolTeachers> alumniSchoolTeachers = alumniSchoolService.getPageTeachers(pageSize,pageNum);
//    Map<String, List<AlumniSchoolTeachers>> map = Maps.newHashMapWithExpectedSize(20);
//    map.put("list", alumniSchoolTeachers);
//    return CommonResult.success(map);
//  }

  @ApiOperation("老师分页")
  @RequestMapping(value = "/pageteachers", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult<CommonPage<AlumniSchoolTeachers>> getPageTeachers(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {

    List<AlumniSchoolTeachers> alumniSchoolTeachers = alumniSchoolService.getPageTeachers(pageSize,pageNum);
    return CommonResult.success(CommonPage.restPage(alumniSchoolTeachers));
  }

  @ApiOperation("老师详情")
  @RequestMapping(value = "/teacher", method = RequestMethod.GET)
  @ResponseBody
  public CommonResult<AlumniSchoolTeachers> getTeacher(Long id) {

    AlumniSchoolTeachers alumniSchoolTeachers = alumniSchoolService.getTeacher(id);
    return CommonResult.success(alumniSchoolTeachers);
  }

}
